package com.admin.business.background.venusEmployeeSuspension;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 员工停职记录
 * @create: 2023-10-23 14:31:53
 **/
@Service("venusEmployeeSuspensionService")
@Slf4j
public class VenusEmployeeSuspensionService{

    @Resource
    VenusEmployeeSuspensionDao venusEmployeeSuspensionDao;

    /**
     * 添加员工停职记录,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:员工系统用户ID
     *                   - org_id:员工公司ID
     *                   - emp_id:员工ID
     *                   - login_sign:1不可以登录、2可以登录
     *                   - show_official:1可以在企业官网展示、2不可以在企业官网展示
     *                   - end_time:停职截止时间
     *                   - remark:停职说明
     *                   - sys_user_id:操作人
     *                   - create_time:创建时间
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return addVenusEmployeeSuspension(CDO cdoRequest) {
        venusEmployeeSuspensionDao.addVenusEmployeeSuspension(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新员工停职记录数据
     *
     * @param cdoRequest - id:
     *                   - user_id:员工系统用户ID
     *                   - org_id:员工公司ID
     *                   - emp_id:员工ID
     *                   - login_sign:1不可以登录、2可以登录
     *                   - show_official:1可以在企业官网展示、2不可以在企业官网展示
     *                   - end_time:停职截止时间
     *                   - remark:停职说明
     *                   - sys_user_id:操作人
     *                   - create_time:创建时间
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return updateVenusEmployeeSuspensionById(CDO cdoRequest) {
        venusEmployeeSuspensionDao.updateVenusEmployeeSuspensionById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除员工停职记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusEmployeeSuspensionById(CDO cdoRequest){
        int count = venusEmployeeSuspensionDao.deleteVenusEmployeeSuspensionById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除员工停职记录数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusEmployeeSuspension(CDO cdoRequest) {
        int count = venusEmployeeSuspensionDao.deleteVenusEmployeeSuspension(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取员工停职记录数据
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusEmployeeSuspensionById(CDO cdoRequest) {
        CDO cdoMapperResult = venusEmployeeSuspensionDao.getVenusEmployeeSuspensionById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取员工停职记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusEmployeeSuspensionListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusEmployeeSuspensionDao.getVenusEmployeeSuspensionListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusEmployeeSuspensionDao.getVenusEmployeeSuspensionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取员工停职记录数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusEmployeeSuspensionListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusEmployeeSuspensionDao.getVenusEmployeeSuspensionListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusEmployeeSuspensionDao.getVenusEmployeeSuspensionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
